package com.acwing.partition43;

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author rkc
 * @date 2022/7/4 15:55
 */
public class AC4276擅长C {

    private static final int N = 10, M = 60;
    private static char[][] g = new char[N][M];
    private static Map<Character, char[][]> map = new HashMap<>(26);

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        for (int i = 0; i < N; i++) Arrays.fill(g[i], ' ');
        for (char c = 'A'; c <= 'Z'; c++) {
            char[][] p = new char[7][5];
            for (int i = 0; i < 7; i++) {
                String s = reader.readLine();
                for (int j = 0; j < 5; j++) {
                    p[i][j] = s.charAt(j);
                }
            }
            map.put(c, p);
        }
        char[] str = reader.readLine().toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length; i++) {
            if (isUpper(str[i])) sb.append(str[i]);
            else if (i > 0 && !isUpper(str[i]) && isUpper(str[i - 1])) sb.append(str[i]);
        }
        if (isUpper(sb.charAt(sb.length() - 1))) sb.append('.');
        String s = sb.toString();
        for (int i = 0, idx = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (isUpper(c)) {
                fill(idx++, map.get(c));
            } else {
                for (int a = 0; a < 7; a++) {
                    for (int b = 0; b < 5 * idx + idx - 1; b++) {
                        writer.write(g[a][b]);
                    }
                    writer.write("\n");
                }
                for (int j = 0; j < N; j++) Arrays.fill(g[j], ' ');
                if (i != s.length() - 1) writer.write("\n");
                idx = 0;
            }
        }
        writer.flush();
    }

    private static void fill(int k, char[][] p) {
        for (int i = 0; i < 7; i++) {
            for (int j = k * 5 + k, x = 0; j < k * 5 + k + 5; x++, j++) {
                g[i][j] = p[i][x];
            }
        }
    }

    private static boolean isUpper(char c) {
        return c >= 'A' && c <= 'Z';
    }
}
